/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.controlcontributions;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;

public abstract class NewBaseNoteContribution extends WorkbenchWindowControlContribution {
	
	private String mLabelTitle;
	
	protected Text mInputText;
	
	public NewBaseNoteContribution(String labelTitle) {
		super();
		mLabelTitle = labelTitle;
	}

	@Override
	protected Control createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		GridLayout containerGL = new GridLayout(3, false);
		containerGL.marginHeight = 0;
		container.setLayout(containerGL);
		GridData containerGD = new GridData(SWT.FILL, SWT.FILL, true, true);
		container.setLayoutData(containerGD);
		
		Label labelTitle = new Label(container, SWT.NONE);
		labelTitle.setText(mLabelTitle);
		labelTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
		
		mInputText = new Text(container, SWT.BORDER);
		GridData gl = new GridData(SWT.FILL, SWT.CENTER, true, true);
		gl.minimumWidth = 150;
		mInputText.setLayoutData(gl);
		
		mInputText.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				processAction();				
			}
		});
		
		return container;
	}
	
	public abstract void processAction();

}
